package com.train.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.train.common.annotation.Log;
import com.train.common.core.controller.BaseController;
import com.train.common.core.domain.AjaxResult;
import com.train.common.enums.BusinessType;
import com.train.user.domain.UserPlanItem;
import com.train.user.service.UserPlanItemService;
import com.train.common.utils.poi.ExcelUtil;
import com.train.common.core.page.TableDataInfo;

/**
 * 计划项目Controller
 *
 * @author train
 * @date 2025-11-15
 */
@RestController
@RequestMapping("/plan/item")
public class UserPlanItemController extends BaseController
{
    @Autowired
    private UserPlanItemService userPlanItemService;

    /**
     * 查询计划项目列表
     */
    @PreAuthorize("@ss.hasPermi('plan:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserPlanItem userPlanItem)
    {
        startPage();
        List<UserPlanItem> list = userPlanItemService.selectUserPlanItemList(userPlanItem);
        return getDataTable(list);
    }

    /**
     * 导出计划项目列表
     */
    @PreAuthorize("@ss.hasPermi('plan:item:export')")
    @Log(title = "计划项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserPlanItem userPlanItem)
    {
        List<UserPlanItem> list = userPlanItemService.selectUserPlanItemList(userPlanItem);
        ExcelUtil<UserPlanItem> util = new ExcelUtil<UserPlanItem>(UserPlanItem.class);
        util.exportExcel(response, list, "计划项目数据");
    }

    /**
     * 获取计划项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('plan:item:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(userPlanItemService.selectUserPlanItemByItemId(itemId));
    }

    /**
     * 新增计划项目
     */
    @PreAuthorize("@ss.hasPermi('plan:item:add')")
    @Log(title = "计划项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserPlanItem userPlanItem)
    {
        return toAjax(userPlanItemService.insertUserPlanItem(userPlanItem));
    }

    /**
     * 修改计划项目
     */
    @PreAuthorize("@ss.hasPermi('plan:item:edit')")
    @Log(title = "计划项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserPlanItem userPlanItem)
    {
        return toAjax(userPlanItemService.updateUserPlanItem(userPlanItem));
    }

    /**
     * 删除计划项目
     */
    @PreAuthorize("@ss.hasPermi('plan:item:remove')")
    @Log(title = "计划项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(userPlanItemService.deleteUserPlanItemByItemIds(itemIds));
    }
}
